<?php
/**
 *      [迷你云] (C)2009-2012 南京恒为网络科技.
 *   软件仅供研究与学习使用，如需商用，请访问www.miniyun.cn获得授权
 * 
 */
?>
<?php

class AdminApiController extends CAdminController
{
	public $layout='//layouts/admin';

	public function actionPvStat()
	{
		$statForm        = new PvStatForm();
		$statForm->model = new APIPv();
		if(Yii::app()->request->isPostRequest){
			$statForm->startDate = $_POST['PvStatForm']["startDate"];
			$statForm->endDate   = $_POST['PvStatForm']["endDate"];
			$statForm->initData();
		}else{
			$statForm->initData();		}
		$this->render('pvStat',array(
             "data"=>$statForm,
		));
	}
	public function actionPerStat(){
		$statForm        = new PerStatForm();
		$statForm->model = new APIPv();
		if(Yii::app()->request->isPostRequest){
			$statForm->startDate = $_POST['PerStatForm']["startDate"];
			$statForm->endDate   = $_POST['PerStatForm']["endDate"];
			$statForm->initData();
		}else{
			$statForm->initData();		}
		$this->render('perStat',array(
             "data"=>$statForm,
		));
	}
	
	public function actionErrorLog(){
		$model    = new ApiErrorLogListForm();
		$errorLog = new APIErrorLog();
		$this->render('errorLogList',array(
            'model'=>$model,
            'count'=>$errorLog->count(),		));
	}
	
	public function actionErrorLogClean()
	{
		if(Yii::app()->request->isPostRequest){
			APIErrorLog::model()->deleteAll();
			$this->redirect(Yii::app()->createUrl("adminApi/errorLog"));
		}else{
			$this->render('errorLogClean');
		}
	}
	
	public function actionExportErrorLog(){
		$page = $pageIndex = Yii::app()->request->getParam("page",1);
		$data = APIErrorLog::model()->findAll(array(
            'order'     =>"updated_at desc",
            'limit'     =>10,
            'offset'    =>($page-1)*10,
		 ));
		Yii::import('application.extensions.phpexcel.JPhpExcel');
		$xls = new JPhpExcel('UTF-8', false, 'Api Error Log');
		$xls->addArray($data);
		$xls->generateXML('Api-Error-Log');
	}
}